﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Meqs.Entity;
using Meqs.Logic.Interface;
using System.Collections.Generic;

public partial class TeacherEval_Student_CauseTeacherEval_Left : ScoreInputBasePage
{
    //protected int schoolYear = 0, term = 0,month= 0;
    protected int evalId = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //schoolYear = SchoolCommon.Sch_SchoolInfo.SchoolYear;
            //term = SchoolCommon.Sch_SchoolInfo.SchoolTerm;
            //ITermInfoLogic logic = Container<ITermInfoLogic>.Instance;
            //List<TermInfo> info = (List<TermInfo>)logic.FindTermInfo(SchoolMark, schoolYear, term);
            //if(info != null && info.Count > 0)
            //{
            //    month = info[0].StartDate.Value.Month;
            //}
            
        }
    }
    protected int firstTeacher = 0;
    protected string first
    {
        get
        {
            if (firstTeacher==0)
            {
                return "";
            }
            return "Nav(" + firstTeacher + ",0);";
        }
    }
    protected string GetMenu()
    {
        evalId = GetCauseTeachHistoryId();
        string str = "<ul>";
        StudentInfo stus = Container<IStudentInfoLogic>.Instance.FindById(Common.GetUserInfo().UID);
        if (stus!=null)
        {
            ClsInfo cls = Container<IClsInfoLogic>.Instance.FindById(stus.ClsID);
            TeacherInfo header = Container<ITeacherInfoLogic>.Instance.FindById(cls.HeaderID);
            Hashtable th = new Hashtable();
            th.Add("ClassID",stus.ClsID);
            IList<TeacherInfo> teachers = Container<ITeacherInfoLogic>.Instance.FindClassTeachers(th);
            
            //获取登陆学生所在班级评价的老师是否已经被评估  add by lxy 2010 04 26
            ITeacherEvalSubmitRecordLogic submitLogic = Container<ITeacherEvalSubmitRecordLogic>.Instance;
            List<TeacherEvalSubmitRecord> submitList = (List<TeacherEvalSubmitRecord>)submitLogic.ValidateTeachIsEvaluate(evalId, Common.GetConstSchoolMark(), stus.ClsID, Common.GetUserInfo().UID);
            if (submitList == null)
                submitList = new List<TeacherEvalSubmitRecord>();

            int index = 0;
            foreach (TeacherInfo ti in teachers)
            {
                if (index == 0)
                {
                    firstTeacher = ti.RID;
                }

                //若是有评估数据的教师 则加载显示图标
               
                TeacherEvalSubmitRecord item = submitList.Find(delegate(TeacherEvalSubmitRecord ts) {return  ts.TeacherID == ti.RID; });
                if(item != null && item.ManagerID == Common.GetUserInfo().UID)
                    str += "<dd><li id=" + index + "_" + ti.RID + " historyId='" + evalId + "' teacherName='" + ti.TeachName + "' onclick='Nav(" + ti.RID + "," + index + ");'><a onclick='' title='' ><span ><img style='padding-top:5px'  src='../../Common/images/pass.gif' />&nbsp;&nbsp;" + ti.TeachName + "</span></a></li></dd>";
                else
                    str += "<dd><li id=" + index + "_" + ti.RID + " historyId='" + evalId + "' teacherName='" + ti.TeachName + "' onclick='Nav(" + ti.RID + "," + index + ");'><a onclick='' title='' ><span >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + ti.TeachName + "</span></a></li></dd>";
                index++;
            }

        }
        str += "</ul>";
        return str;
    }

    /// <summary>
    /// 获取学生评教的历史评估id
    /// </summary>
    /// <returns></returns>
    private static int GetCauseTeachHistoryId()
    {
        string keyWord = TeacherEvalHistory.CauseStudentSurvey_Term_Eval;
        ITeacherEvalHistoryLogic logic = Container<ITeacherEvalHistoryLogic>.Instance;

        Hashtable table = new Hashtable();
        table.Add("SchoolMark", SchoolMark);
        table.Add("SchoolYear",SchoolCommon.Sch_SchoolInfo.SchoolYear);
        table.Add("Term",SchoolCommon.Sch_SchoolInfo.SchoolTerm);
        table.Add("KeyWord", keyWord);

        List<TeacherEvalHistory> history = (List<TeacherEvalHistory>)logic.FindAll(table);
        if (history != null && history.Count > 0)
        {
            return history[0].RID;
        }
        else
            return 0;
    }

    /// <summary>
    /// 重新载入left导航
    /// </summary>
    /// <returns></returns>
    [System.Web.Services.WebMethod]
    public static string ReloadMenu(int currEvalId)
    {
        //int evalId = GetCauseTeachHistoryId();
        string str = "<ul>";
        StudentInfo stus = Container<IStudentInfoLogic>.Instance.FindById(Common.GetUserInfo().UID);
        if (stus != null)
        {
            ClsInfo cls = Container<IClsInfoLogic>.Instance.FindById(stus.ClsID);
            TeacherInfo header = Container<ITeacherInfoLogic>.Instance.FindById(cls.HeaderID);
            Hashtable th = new Hashtable();
            th.Add("ClassID", stus.ClsID);
            IList<TeacherInfo> teachers = Container<ITeacherInfoLogic>.Instance.FindClassTeachers(th);

            //获取登陆学生所在班级评价的老师是否已经被评估  add by lxy 2010 04 26
            ITeacherEvalSubmitRecordLogic submitLogic = Container<ITeacherEvalSubmitRecordLogic>.Instance;
            List<TeacherEvalSubmitRecord> submitList = (List<TeacherEvalSubmitRecord>)submitLogic.ValidateTeachIsEvaluate(currEvalId, Common.GetConstSchoolMark(), stus.ClsID, Common.GetUserInfo().UID);
            if (submitList == null)
                submitList = new List<TeacherEvalSubmitRecord>();

            int index = 0;
            foreach (TeacherInfo ti in teachers)
            {
                //若是有评估数据的教师 则加载显示图标

                TeacherEvalSubmitRecord item = submitList.Find(delegate(TeacherEvalSubmitRecord ts) { return ts.TeacherID == ti.RID; });
                if (item != null && item.ManagerID == Common.GetUserInfo().UID)
                    str += "<dd><li id=" + index + "_" + ti.RID + " historyId='" + currEvalId + "' teacherName='" + ti.TeachName + "' onclick='Nav(" + ti.RID + "," + index + ");'><a onclick='' title='' ><span ><img style='padding-top:5px'  src='../../Common/images/pass.gif' />&nbsp;&nbsp;" + ti.TeachName + "</span></a></li></dd>";
                else
                    str += "<dd><li id=" + index + "_" + ti.RID + " historyId='" + currEvalId + "' teacherName='" + ti.TeachName + "' onclick='Nav(" + ti.RID + "," + index + ");'><a onclick='' title='' >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span >" + ti.TeachName + "</span></a></li></dd>";
                index++;
            }

        }
        str += "</ul>";
        return str;
    }
}
